//
//  FKShareNowView.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/21.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKShareNowView.h"

@interface FKShareNowView ()

@end

@implementation FKShareNowView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews
{
    self.backgroundColor = fkColorAlpha(0, 0, 0, 0.5);
    
    UIButton *closeBtn = [UIButton fk_btnWithTarget:self action:@selector(dismiss) img:[UIImage imageNamed:@"Close"]];
    [self addSubview:closeBtn];
    closeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    closeBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    
//    UIView *container = [[UIView alloc] init];
    
    UIImageView *container = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"share_bg"]];
    [self addSubview:container];
    container.userInteractionEnabled = true;
    [container fk_viewCornerRadius:5 borderWidth:0 borderColor:nil];
    
    UIButton *shareBtn = [UIButton fk_btnWithTarget:self action:@selector(shareBtnClicked) font:fk_adjustFont(13) normalTitle:@"立即分享" normalTitleColor:[UIColor whiteColor] selectedTitle:nil selectedTitleColor:nil normalImg:nil selectedImg:nil bgImg:[UIImage fk_imageWithColor:fkMainColor] selectedBgImg:nil];
    [container addSubview:shareBtn];
    
    [container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(262));
        make.height.offset(fk_adjustW(378));
        make.centerX.centerY.offset(0);
    }];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(container);
        make.bottom.equalTo(container.mas_top).offset(-6);
        make.width.height.offset(fk_adjustW(36));
    }];
    [shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(fk_adjustW(220));
        make.height.offset(fk_adjustW(40));
        make.bottom.offset(fk_adjustW(-25));
        make.centerX.offset(0);
    }];
}

- (void)shareBtnClicked
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"weixin://"]];
    [self dismiss];
}

- (void)show
{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    self.frame = [UIScreen mainScreen].bounds;
    [window addSubview:self];
    
}

- (void)dismiss
{
    [self removeFromSuperview];
}

@end
